<!DOCTYPE html>
<html>
	<head>
		<#include "/templates/commons/head.html">
		<script type="text/javascript">
			/**
			*点击保存按钮保存页面信息
			*/
			function save(){
			  	if(!$("#opForm").validateForm()){
					return;
			   	}
			    var method = document.opForm.method.value;
				var messages = "";
				if(method=="addSave"){
					messages = "您是否确定要添加？";
				}else if(method=="editSave"){
					messages = "您是否确定要修改？";
				}
				layer.confirm(messages, {
					    btn: ['确定', '取消']
					}, function() {
					    document.opForm.action = "${ctx!}/MenuController/" + method + ".do";
						document.opForm.submit();
					}, function() {
				});
			}
			
			/**
			*点击菜单级别联动父级菜单
			*/
			function changePmenuFun(obj){
			    Common.postNetwork("${ctx!}/MenuController/getPmenuList.do", {"param_menuLevel":obj.value,"selectedValue":""}, function(data) {
					$("#div-pmenu").empty();
					$.each(data, function(i, o) {
					    $("#div-pmenu").append('<input type="radio" name="parentMenu" value="' + o.menuId + '" title="' + o.menuName + '" /><br />');
					});
					form.render();
			    });
			}
			/**
			*点击返回按钮进入用户列表页面
			*/
			function goBack(){
			    /* var menuLevel =document.getElementById("menuLevel").value 
			    if( menuLevel == ""){
					document.getElementById("menuLevel").value=0;
				} */
				document.opForm.action = "${ctx!}/MenuController/getMenuList.do";
				document.opForm.submit();
			}

			/*
			 * 使用ready()方法替代$(function() {}) 和 $(document).ready(function() {}) 以及 window.onload 等初始化方法
			 */
			function ready() {
			    //初始化selectchange事件
				form.on('select(changePmenu)', function(data) {
				    changePmenuFun(data);
				});
			    
				/* $("input:checkbox[name='menuBean.siIds']").each(function() {
					$(this).click(function() {
						if($(this).is(":checked")) {
							var flag = true;
							$("input:checkbox[name='menuBean.siIds']").each(function() {
								if(!$(this).is(":checked")) {
									flag = false;
								}
							});
							if(flag) {
								$("input:checkbox:eq(0)").attr("checked",flag);
							}
						} else if(!$(this).is(":checked")) {
							$("input:checkbox:eq(0)").attr("checked",false);
						}
					});
				}); */
			};
		</script>
	</head>
	<body>
		<div id="div-body" class="body addPage">
			<div class="hid-scroller-body">
				<!-- 标题 Start -->
				<#include "/templates/commons/menuPath.html">
				<!-- 标题 End -->
				<form id="opForm" name="opForm" method="post" class="layui-form">
					<!-- list页面搜索条件 Start -->
					<input type="hidden" name="param_menuName" value="${Request.param_menuName!''}"/>
					<input type="hidden" name="param_menuPath" value="${Request.param_menuPath!''}"/>
					<!-- list页面搜索条件 End -->
					<!-- add||edit页面信息Start -->
					<#if method == 'add'>
						<input type="hidden" name="method" value="addSave"/>
					<#else>
						<input type="hidden" name="method" value="editSave"/>
					</#if>
					<input type="hidden" name="menuId" value="${menuBean.menuId!''}"/>
					<!-- add||edit页面信息End -->
					<!-- 添加信息 Form Start -->
					<div class="main-container">
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>菜单名称</label>
							<div class="layui-input-block">
								<input type="text" name="menuName" value="${menuBean.menuName!''}" notEmpty="true" isValidate="true" leng="20" placeholder="请输入菜单名称" class="layui-input" lay-verify="title"/>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>默认菜单</label>
							<div class="layui-input-block">
								<@dict type="yes_no">
									<#list dictList as dict>
										<input type="radio" name="isDefault" value="${dict.code}"  title="${dict.name}" <#if (menuBean.isDefault?? && dict.code == menuBean.isDefault?c)>checked</#if>/>
									</#list>
								</@dict>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>菜单级别</label>
							<div class="layui-input-inline">
								<#if method == 'add'>
									<select name="menuLevel" lay-filter="changePmenu">
										<@dict type="menu_level">
											<option value="">请选择菜单级别</option>
											<#list dictList as dict>
												<option value="${dict.code}">${dict.name}</option>
											</#list>
										</@dict>
									</select>
								<#else>
									<input type="hidden" name="menuLevel" value="${menuBean.menuLevel!''}"/>
									<span class="layui-input"><@dict type="menu_level" value="${menuBean.menuLevel!}">${typeName}</@dict></span>
								</#if>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>菜单类型</label>
							<div class="layui-input-inline">
								<#if method == 'add'>
									<select name="menuType">
										<option value="">请选择菜单类型</option>
										<@dict type="menu_type">
											<#list dictList as dict>
												<option value="${dict.code}">${dict.name}</option>
											</#list>
										</@dict>
									</select>
								<#else>
									<input type="hidden" name="menuType" value="${menuBean.menuType!''}"/>
									<span class="layui-input"><@dict type="menu_type" value="${menuBean.menuType!}">${typeName!}</@dict></span>
								</#if>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>菜单排序</label>
							<div class="layui-input-block">
								<input type="text" name="menuOrder" value="${menuBean.menuOrder!''}" isValidate="true" isnum="true" leng="4" placeholder="请输入菜单排序" class="layui-input" lay-verify="title"/>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>请求路径</label>
							<div class="layui-input-block">
								<input type="text" name="menuPath" value="${menuBean.menuPath!''}" isValidate="true" notEmpty="true" leng="100" placeholder="请输入请求路径" class="layui-input" lay-verify="title"/>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">菜单图片</label>
							<div class="layui-input-block">
								<input type="text" name="menuImage" value="<#if menuBean.menuImage??>${menuBean.menuImage?html}<#else></#if>" isValidate="true" leng="60" placeholder="请输入菜单图片" class="layui-input" lay-verify="title"/>
							</div>
						</div>
						<div class="layui-form-item layui-form-text">
							<label class="layui-form-label">菜单描述</label>
							<div class="layui-input-block">
								<textarea name="remark" placeholder="请输入菜单描述" class="layui-textarea">${menuBean.remark!''}</textarea>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>授权机构</label>
							<div class="layui-input-block">
								<#list SILIST as baseBean>
									<input type="checkbox" name="siIds" <#if menuBean.siIds??>${menuBean.siIds?seq_contains(baseBean.code!)?string("checked", "")}</#if> value="${baseBean.code}" title="${baseBean.name}">
								</#list>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>父级菜单</label>
							<div class="layui-input-block" id="div-pmenu">
								<#if method == 'edit'>
									<input type="hidden" name="parentMenu" value="${menuBean.parentMenu!''}"/>
									<span class="layui-input">${menuBean.parentMenu!''}</span>
								</#if>
							</div>
						</div>
					</div>
					<!-- 添加信息 Form End -->
					<!-- 按钮区域 Start -->
					<div class="main-button">
						<div class="layui-input-block">
							<#if (Session.CUR_MENU.addRole==1 && method=='add') || (Session.CUR_MENU.updateRole==1 && method=='edit') >
								<button type="button" class="layui-btn" onClick="save();"><i class="layui-icon">&#xe642;</i>保存</button>
							</#if>
							<button type="button" class="layui-btn layui-btn-primary" onClick="goBack();"><i class="layui-icon">&#xe65c;</i>返回</button>
						</div>
					</div>
					<!-- 按钮区域 End -->
				</form>
			</div>
		</div>
	</body>
</html>